<template>
  <div class="login-account">
    <el-form label-width="65px" :rules="rules" :model="info" ref="formRef">
      <el-form-item label="手机号" prop="sjh">
        <el-input v-model="info.sjh" />
      </el-form-item>
      <el-form-item label="验证码" prop="yzm">
        <div class="yzm">
          <el-input v-model="info.yzm" />
          <el-button type="primary" class="yzmbtn">获取验证码</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script lang="ts">
import { defineComponent, reactive, ref } from 'vue'
import { rules } from '../config/iphone-config'
import { ElForm } from 'element-plus'
import { useStore } from 'vuex'

export default defineComponent({
  setup() {
    const info = reactive({
      sjh: '',
      yzm: ''
    })

    // 规则在config文件中

    const formRef = ref<InstanceType<typeof ElForm>>()
    const store = useStore()
    const loginAction = () => {
      formRef.value?.validate((valid) => {
        if (valid) {
          console.log('手机登录')
          // 1.是否记住密码
          // 2.登录验证
          store.dispatch('login/iponeLoginAction', { ...info })
          // 3.跳转主页
          // router.push('/main')
        }
      })
    }

    return {
      info,
      rules,
      formRef,
      loginAction
    }
  }
})
</script>

<style scoped lang="less">
.yzm {
  display: flex;
}
.yzmbtn {
  margin-left: 10px;
}
</style>
